{% extends "cms/cms_base.html" %}

{% block pagetitle%}
this is index
{% endblock %}

{%block head%}
<style>
    #resetpassword{
        width:500px;
    }
    .resetpassword{
        line-height: 50px;
        magin-top:40px;
    }
    .btn-primary{
        margin:12px auto;
    }

</style>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
$(document).ready(function(eq){
    $('#submit').click(function(event){
        event.preventDefault()
        var oldpwd=$("input[name=password]").val()
        var password1=$("input[name=new_password]").val()
        var password2=$("input[name=new_password2]").val()
    if(password1.length<=5){
        swal({
            icon:"error",
            text:"密码长度小于6"
        })
    }
    if(password2==password1){
    var csrftoken = $('meta[name=csrf_token]').attr('content')
        $.ajax({
            url:"",
            type:"POST",
            headers: {"X-CSRFToken":csrftoken},
            data:{
                "oldpwd":oldpwd,
                'newpwd1':password1
            },
            success:function(data){
                console.log(data)
                icon="success"
                title="Success"
                if(data.code==400){
                    icon="error"
                    title="Error"
                }
                swal({
                      title: "Success!",
                      text: data.message,
                      icon: icon,
                    });
            },
            error:function (data) {
                console.log(data)
                swal({
                    title:"Error!",
                    text:data.message,
                    icon:'error'

                })
            }
        })
        $("input[name=password]").val("")
        $("input[name=new_password]").val("")
        $("input[name=new_password2]").val("")
    }
    else{
        swal({
            icon:"error",
            text:"两次密码不一致"
        })
        $("input[name=new_password]").val("")
        $("input[name=new_password2]").val("")
    }


    })

})
</script>

{%endblock%}

{% block content %}
<form method="post" id="resetpassword">
    <div class="form-group input-group resetpassword">
  <span class="input-group-addon">你的密码</span>
  <input type="text" class="form-control" placeholder="old password" name="password" aria-describedby="basic-addon1">
</div>
<div class="form-group input-group resetpassword">
  <span class="input-group-addon">新密码</span>
  <input type="text" class="form-control" placeholder="Username" name="new_password" aria-describedby="basic-addon1">
</div>
<div class="form-group input-group resetpassword">
  <span class="input-group-addon">新密码</span>
  <input type="text" class="form-control" placeholder="Username" name="new_password2" aria-describedby="basic-addon1">
</div>
    <input type="submit" id="submit" class="btn btn-primary" name="submit" value="确认">
</form>

{% endblock%}